# -*- coding: utf-8 -*-


import sys

from PyQt5.QtGui import QIcon, QCloseEvent
from PyQt5.QtWidgets import QMainWindow, QApplication, QMenu, QAction, QMenuBar

from widget.trayicon import TrayIcon, Qt
from windows.datamangement import DataMangement


class MainWindow(QMainWindow):


    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.initUI()

    def initUI(self):
        self.resize(1000, 600)
        self.statusBar().showMessage('© 2018 burgeon.cn 版权所有')
        self.setWindowTitle('FC-POS')
        self.setWindowIcon(QIcon("bitbug_favicon.ico"))

        ti = TrayIcon(self)
        # 设置消息提示点击事件
        ti.mClied = self.mClied
        ti.show()

        # self.fileOpenAction = QAction(QIcon("main.png"), self.tr("数据库管理"), self)
        # self.fileOpenAction.setShortcut("Ctrl+O")
        # self.fileOpenAction.setStatusTip(self.tr("数据库管理"))
        # fileMenu = self.menuBar().addMenu("文件")
        # fileMenu.addAction(self.fileOpenAction)
        # self.fileOpenAction.triggered.connect(self.mActionClied)


        ti.showMessage("测试", "我是外部消息")

    def mClied(self):
        print("消息点击")
        # 判断是否最小化状态，是就显示正常状态
        if self.windowState() == Qt.WindowMinimized:
            self.showNormal()
        #显示
        if self.isVisible():
            pass
        else:
            self.show()

    def mActionClied(self):
        print("菜单点击")
        self.another = DataMangement()
        self.another.show()

        # # 判断是否最小化状态，是就显示正常状态
        # if self.windowState() == Qt.WindowMinimized:
        #     self.showNormal()
        # # 显示
        # if self.isVisible():
        #     pass
        # else:
        #     self.show()

    def closeEvent(self, event):
        print("关闭点击")
        print(type(event))
        if self.isVisible():
            event.ignore()
            # mac任务栏会显示并且点击打不开？？？？？？？？？？？？？？？？？？？？？？？？？？？？？
            self.hide()
            # #最小化，注意：最小话并不是hide状态，其实还是show的状态。
            # self.showMinimized()
        else:
            event.accept()

if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = MainWindow()
    ex.show()
    sys.exit(app.exec_())

